package com.c2soft.nepalcmx.controller;

import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import lombok.extern.log4j.Log4j2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.c2soft.nepalcmx.command.BrokeOrderCommand;
import com.c2soft.nepalcmx.command.NetPositionCommand;
import com.c2soft.nepalcmx.command.OrderCommand;
import com.c2soft.nepalcmx.services.BrokeOrderMgmtService;
import com.c2soft.nepalcmx.services.OrderMgmtService;

@Controller
@RequestMapping("/broker")
public class BrokeOrderMgmtController {
	Logger logger = LogManager.getLogger(BrokeOrderMgmtController.class.getName());
	
	@Autowired
	private BrokeOrderMgmtService orderService;
	
	
	@RequestMapping(value = "/show")
	public String show() {
		return "testOrder";
	}

	@RequestMapping(value = "/buy",method=RequestMethod.POST, headers = "Accept=application/json")
	@ResponseBody
	public String buy(@RequestBody BrokeOrderCommand buyOrder) {
		
		logger.debug(buyOrder);
		logger.debug(buyOrder.getUserId());
		orderService.buyService(buyOrder);
		return "success";
	}

	@RequestMapping(value = "/sell", method = { RequestMethod.GET,RequestMethod.POST },  headers = "Accept=application/json")
	@ResponseBody
	public String sell(@RequestBody BrokeOrderCommand sellOrder) {
		
		
		logger.debug(sellOrder);
		logger.debug(sellOrder.getUserId());
		orderService.sellService(sellOrder);
		return "success";
	}
	
@RequestMapping(value = "/buyorderMgmt",method=RequestMethod.GET, headers = "Accept=application/json")
	
	public @ResponseBody List<NetPositionCommand> getOrders(@RequestParam("brokerId") String brokerId) {
		
		
		
		List<NetPositionCommand> accountDetail=orderService.getBuyOrder(brokerId);
		return accountDetail;
	}

@RequestMapping(value = "/buyorderMgmtX",method=RequestMethod.GET, headers = "Accept=application/json")

public @ResponseBody List<NetPositionCommand> getExchangeOrders() {
	List<NetPositionCommand> accountDetail=orderService.getExchangeBuyOrder();
	return accountDetail;
}

}
